package pers.cz.postgirl.core.connect.redis;

import pers.cz.postgirl.core.connect.Connection;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @program: postgirl-collection-client
 * @description: redis连接
 * @author: Cheng Zhi
 * @create: 2022-07-31 12:25
 **/
public class RedisConnection extends Connection {
    Jedis jedis;

    public RedisConnection(Object jedisPool) {

        if (jedisPool == null) {
            throw new IllegalArgumentException("参数异常");
        }
        JedisPool o = (JedisPool) jedisPool;
        jedis = o.getResource();

    }

    @Override
    public void close() {
        jedis.close();
    }

    @Override
    public void insert(String key, byte[] content) {

    }

    @Override
    public String get(String key) {
        return jedis.get(key);
    }

    @Override
    public byte[] getBytes(String key) {
        return new byte[0];
    }

    @Override
    public Long autoIncrement(String key) {
        return jedis.incr(key);
    }

    @Override
    public void expire(String key, Integer time) {
        jedis.expire(key, time);
    }

    @Override
    public void realInsert(String context) {

    }

    @Override
    public void realSet(String key, String value) {
        jedis.set(key,value);
    }

    @Override
    public void realInsert(String key, String context) {
        jedis.lpush(key, context);
    }

    @Override
    public void realInsert(String ip, String fileName, String content) {

    }

}
